# coding=utf-8
import time
from framework.base_page import BasePage
from framework.logger import MyLog
import random
import logger


class CommunityList(BasePage):

    dynamic_tag = "predicate=>type == 'XCUIElementTypeButton' AND label == '动态'"
    add_newactivity = "xpath=>//XCUIElementTypeButton[@name='Community NewActivity']"
    check_newactivity = "xpath=>//XCUIElementTypeButton[@name='Community NewActivity']"
    hengqing = "xpath=>//XCUIElementTypeButton[@name='行情']"


    # 社区
    btn_community = 'id=>com.gelonghui.glhapp:id/iv_tab_icon'
    # 我有话说
    btn_speak = 'id=>com.gelonghui.glhapp:id/tv_want_speak'
    # 我也要讲两句
    btn_publish = 'id=>com.gelonghui.glhapp:id/tv_publish'
    
    # 标题
    input_title = 'id=>com.gelonghui.glhapp:id/title'
    # 正文
    input_txt = 'id=>com.gelonghui.glhapp:id/content'
    # 上传照片
    upload_photo = 'id=>com.gelonghui.glhapp:id/img'
    # 本地
    btn_Local = 'id=>com.gelonghui.glhapp:id/btn_choose_local_pic'
    # 选择图片
    select_photo = 'id=>com.gelonghui.glhapp:id/check_view'
    # 确认图片
    btn_confirm = 'id=>com.gelonghui.glhapp:id/button_apply'
    # 发表
    btn_publish = 'class=>android.widget.TextView'
    
    def go_community(self):
        #点击社区
        self.click(self.btn_community)
        logger.info('点击社区')
        time.sleep(1)

    def go_speaking(self):
        # 点击我有话说
        self.click(self.btn_speak)
        logger.info('点击我有话说')
        time.sleep(1)
        # 点击我也要讲两句
        self.click(self.btn_publish)
        logger.info('点击我也要讲两句')
        time.sleep(1)

    def confirm_speaking(self):
        random_number = random.randint(0,1000)
        random_string = random.choice(['天生我材必有用',
                                        '千金散尽还复来',
                                        '君不见黄河之水天上来',
                                        '哈撒给'
                                        ])
        # 输入标题
        self.send_keys(self.input_title('大咖'+random_number))
        logger.info('输入标题')
        time.sleep(1)
        # 输入正文
        self.click(self.input_txt(random_string))
        logger.info('输入正文')
        time.sleep(1)
        #上传图片
        self.click(self.upload_photo)
        logger.info('上传图片')
        time.sleep(1)
        # 选择本地
        self.click(self.btn_Local)
        logger.info('选择本地')
        time.sleep(1)
        # 选择图片
        self.click(self.select_photo)
        logger.info('选择图片')
        time.sleep(1)
        # 确认图片
        self.click(self.btn_confirm)
        logger.info('确认图片')
        time.sleep(1)
        # 发表发言
        self.click(self.btn_publish)
        logger.info('发表发言')
        time.sleep(1)

















    # # 点击顶部"社区"tag
    # def click_dynamic_tag(self):
    #     self.click(self.dynamic_tag)

    # # 点击"新增动态"按钮
    # def click_new_activit(self):
    #     self.click(self.add_newactivity)

    # # 检查
    # def check_new_activit(self):
    #     self.check_element(self.check_newactivity)

    # # 点击行情页
    # def click_hengqing_tag(self):
    #     self.click(self.hengqing)
